fix(flatbuffers): use manual impl Default for struct object types#8947
fix(flatbuffers): use manual impl Default for struct object types#8947RenzoMXD wants to merge 4 commits intogoogle:masterfrom
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
src/idl_gen_rust.cpp
Outdated
| switch (full_type) { | ||
| case ftArrayOfBuiltin: { | ||
| // e.g. [0; 64] for [u8; 64] | ||
| code_ += " {{FIELD}}: [0; " + |
There was a problem hiding this comment.
I'm not a rust person nor do I use our generated code so take what I ask at face value :)
Does this work for arrays of bool?
|
hey @RenzoMXD I think you need to run the script |
Hello, @jtdavis777 I regenerated and left commits. Please kindly review. |
Fix Rust codegen: use manual impl Default for struct object types
Problem
When a FlatBuffers struct contains a fixed-size array with more than 32 elements (e.g.
[ubyte:64]), the generated Rust object API type uses#[derive(Default)]which fails to compile on Rust < 1.61, becauseDefaultwas not implemented for[T; N]whereN > 32until that version.Fix
Changed the Rust code generator (
src/idl_gen_rust.cpp) to emit a manualimpl Defaultfor struct object types instead of#[derive(Default)]. This matches the pattern already used for table object types.The generated default values are:
GetDefaultValue()(0, false, etc.)[0; N](avoids the Default trait bound)::flatbuffers::array_init(|_| Default::default())Code generation changes
Changes were made to
src/idl_gen_rust.cpp.Test
Added
LargeArrayStruct { d:[ubyte:64]; }totests/arrays_test.fbs.Closes #8943